home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17339 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.th-darmstadt.de!news
  2. From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Templates & friends
  5. Date: Mon, 15 Apr 1996 13:06:26 +0200
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Message-ID: <31722DB2.237C228A@intellektik.informatik.th-darmstadt.de>
  8. References: <317211BF.41C6@sonytel.be>
  9. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01 (X11; I; SunOS 4.1.3 sun4m)
  14.  
  15. Philip Rademakers wrote:
  16. > Hi,
  17. > Does anybody know how to declare a friend class that is one of the
  18. > argument classes? I tried the following:
  19. > class X {
  20. > protected:
  21. >   X();
  22. > };
  23. > template<class T>
  24. > class foo {
  25. > private:
  26. >   T* _ptr;
  27. > public:
  28. >   friend class T;
  29. >   foo() { _ptr = new T; }
  30. > };
  31. > The compiler (on SGI) complains that X::X() is not accessible ?
  32.  
  33. Friendship is not symmetrical, i.e. the instance foo<X> of the
  34. generic class declares 'X' as friend of the 'foo<X>' but not
  35. vice versa. Thus 'foo<X>' cannot access non-public parts of
  36. class 'X'.
  37.  
  38.         Enno
  39.